Skip to content

feat(sql-completion): schema-aware autocomplete with dialect switching - #131

Merged
Blankll merged 3 commits into
masterfrom
feat/sql-completion
Aug 6, 2026
Merged

feat(sql-completion): schema-aware autocomplete with dialect switching#131
Blankll merged 3 commits into
masterfrom
feat/sql-completion

Conversation

@Blankll

@Blankll Blankll commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

Adds schema-aware SQL autocomplete to the Monaco editor with per-dialect profiles and metadata-driven suggestions.

What's included

  • 4-layer completion pipeline in src/composables/sqlCompletion/:
    • analyzer.ts — parses the query at the cursor (keywords, FROM clause, table refs, aliases, CTEs)
    • builder.ts — builds suggestions (keywords, functions, tables, columns, schemas, databases) with prefix matching
    • dialects.ts — dialect profiles (postgresql, mysql, mssql, plsql, sqlite, generic sql)
    • provider.ts — monaco completion provider, registered for every SQL dialect id
  • Metadata service (metadata.ts) — 3-level cache (connection objects / columns / derived aliases), injected store loader (browser-safe, no CommonJS require)
  • Wiring: SQLEditor.vue + useMonacoEditor.ts register the provider and push dialect + completion context; QueriesPage.vue computes the active connection/db/schema/dialect context
  • 60 unit tests in src/__tests__/sqlCompletion/

Key fixes found during manual QA

  1. First-mount wiring: immediate watchers fired before editor instantiation → explicitly apply language + completion context in onMounted
  2. Browser-only crash (ReferenceError: Can't find variable: require): replaced CommonJS require('@/store/databaseStore') with injectable setDatabaseStoreLoader registered in main.ts — jest could not catch this
  3. Snapshot staleness: completionContext now tracks the full async metadata dependency graph (meta.databases, meta.schemas[db], meta.tables[db] + every schema-qualified key) so the provider snapshot rebuilds after connect

Post-review fixes (b52ad63)

  1. Syntax highlighting regression: SQLite / SQL Server / Oracle connections render as plain text because Monaco only ships sql/mysql/pgsql grammars. The editor now falls back to the generic sql grammar when hasGrammar(id) is false (at both editor creation and updateLanguage) — completion still resolves the real dialect profile per editor.
  2. Wrong suggestions for schema-qualified words: public.us with a FROM table whose columns were cached returned that table's columns instead of public schema tables. The analyzer no longer falls back to the last FROM table when the qualifier matches neither an alias nor a table (single-segment qualifiers only, quoted segments unquoted before compare).
  3. Provider footgun: getCompletionProvider defaulted to undefined as never; the monacoLike parameter is now required.
  4. Cross-schema column completion limitation documented at the prefetch call site and in metadata.ts (FROM public.users while another schema is active gets no column completion — sync-provider v1 tradeoff; fetchTableColumns() is the async escape).

Validation

  • Full suite: 519/519 jest tests pass, vue-tsc clean, eslint 0 errors, npm run build
  • Live-engine metadata validated against Docker Postgres 16, MySQL 8, SQL Server 2022 (list_databases/schemas/tables/columns)
  • Pre-existing gap (not from this PR): Postgres/MySQL integration tests panic on missing rustls CryptoProvider in the test harness (app binary installs aws_lc_rs::default_provider() internally); SQL Server suite passes 6/8

Out of scope

  • src/components/grid/DataGrid.vue local styling change intentionally left uncommitted

Blankll added 3 commits August 6, 2026 23:41
- Add 4-layer completion pipeline (analyzer/builder/dialects/provider)
- Wire monaco completion providers for all SQL dialects
- Track async-loaded metadata so provider snapshots rebuild after connect
- Register Pinia store loader browser-safely (no CommonJS require)
- 60 unit tests; full suite 515/515
@Blankll
Blankll merged commit 5c6ff32 into master Aug 6, 2026
1 of 3 checks passed
@Blankll
Blankll deleted the feat/sql-completion branch August 6, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant